/*
 * Copyright (c) 2012 swing-on-fire Team
 * 
 * This file is part of Swing-On-Fire (http://code.google.com/p/swing-on-fire), licensed under the terms of the MIT
 * License (MIT).
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.google.code.swingonfire.component.page.old;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;

public abstract class JPageComposite
{

    public static JPageComposite simple()
    {
        return new JPageComposite()
        {

            /**
             * {@inheritDoc}
             */
            @Override
            public void prepare(Graphics2D g, double value, double previousValue, int width, int height)
            {
                int x1 = (int) (previousValue * width);
                int x2 = (int) (value * width);
                int w = x2 - x1;

                if (w <= 0)
                {
                    return;
                }

                if (w < 128)
                {
                    w = 128;
                    x1 = x2 - w;
                }

                g.setComposite(AlphaComposite.DstIn);
                g.setPaint(new LinearGradientPaint(x2 - 128, 0, x2, 0, new float[]{0, 1}, new Color[]{new Color(0, 0, 0, 0),
                    new Color(0, 0, 0, 255)}));
                g.fillRect(x1, 0, w, height);
                
                
                
//
//                g.setComposite(AlphaComposite.DstOut);
//                g.fillRect(x1, 0, w, height);
              
//                if (value > 0) {
//                    return;
//                }
//              g.setComposite(AlphaComposite.DstIn);
//              g.setPaint(new LinearGradientPaint(0, 0, width, 0, new float[]{0, 1}, new Color[]{new Color(0, 0, 0, 0),
//                  new Color(0, 0, 0, 255)}));
//              g.fillRect(0, 0, width, height);

            }

        };
    }

    public abstract void prepare(Graphics2D g, double value, double previousValue, int width, int height);

}
